package com.sali.b_design_pattern.i_iterator_pattern.service.impl;


import com.sali.b_design_pattern.i_iterator_pattern.pojo.Student;
import com.sali.b_design_pattern.i_iterator_pattern.service.StudentCollection;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

// 具体可迭代对象
public class ConcreteStudentCollection implements StudentCollection {

    private List<Student> students = new ArrayList<>();

    public void addStudent(Student student) {
        students.add(student);
    }

    @Override
    public Iterator<Student> iterator() {
        return new ConcreteStudentIterator(students);
    }
}
